package com.example.a828502.Utils;

/**
 * Created by 828502 on 16/5/18.
 */

import android.app.ActionBar;
import android.app.Dialog;
import android.content.Context;
import android.graphics.Paint;
import android.os.Bundle;
import android.text.TextWatcher;
import android.view.View;
import android.view.Window;
import android.widget.Button;
import android.widget.EditText;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.example.a828502.sfdialtestdemo.R;

/**
 * 带输入框的弹出框
 * Created by 828502 on 2016/2/27.
 */
public class InputDialog extends Dialog {

    private Context context;
    private Button mBtnDialogOkAction;

    public InputDialog(Context context) {
        super(context, R.style.dialog);
    }

    public InputDialog(Context context, int theme) {
        super(context, theme);
        this.context = context;
    }

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        requestWindowFeature(Window.FEATURE_NO_TITLE);
        setContentView(R.layout.view_input_dialog);
        TextView mTxtDialogTitle = (TextView) findViewById(R.id.textDialogTitle);
        mtxtInputIP = (EditText) findViewById(R.id.textInputIP);
        mtxtInputPort = (EditText) findViewById(R.id.textInputPort);

        mBtnDialogOkAction = (Button)findViewById(R.id.btnDialogOkAction);
        if (positiveButtonText != null) {
            (mBtnDialogOkAction)
                    .setText(positiveButtonText);
            if (positiveButtonClickListener != null) {
                (mBtnDialogOkAction)
                        .setOnClickListener(new View.OnClickListener() {
                            public void onClick(View v) {
                                positiveButtonClickListener.onClick(v);
                            }
                        });
            }
        } else {
            findViewById(R.id.btnDialogOkAction).setVisibility(
                    View.GONE);
        }

          if (contentView != null) {
            ((LinearLayout) findViewById(R.id.layoutContent))
                    .removeAllViews();
            ((LinearLayout) findViewById(R.id.layoutContent))
                    .addView(contentView, new ActionBar.LayoutParams(ActionBar.LayoutParams.MATCH_PARENT, ActionBar.LayoutParams.FILL_PARENT));
        }

    }

    private String inputIPStr,inputPort;
    private String positiveButtonText;
    private View contentView;
    private EditText mtxtInputIP,mtxtInputPort;
    private View.OnClickListener positiveButtonClickListener;


    public String getIP() {
        inputIPStr = mtxtInputIP.getText().toString();
        return inputIPStr;
    }

    public String getPort() {
        inputPort = mtxtInputPort.getText().toString();
        return inputPort;
    }

    public void setPositiveButton(String positiveButtonText,
                                  View.OnClickListener listener) {
        this.positiveButtonText = positiveButtonText;
        this.positiveButtonClickListener = listener;
    }

}
